<template>
    <el-container style="height: 500px; border: 1px solid #eee">
        <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
            <el-menu >
                <el-submenu index="fun.id" v-for="fun in functions">
                    <template slot="title"><i :class="fun.icon"></i>{{fun.name}}</template>
                    <el-menu-item-group>
                        <el-menu-item index="cfun.id" v-for="cfun in fun.subFunctions">
                            <router-link :to="cfun.url">{{cfun.name}}</router-link>
                        </el-menu-item>
                    </el-menu-item-group>
                </el-submenu>
            </el-menu>
        </el-aside>

        <el-container>
            <el-header style="text-align: right; font-size: 12px">
                <el-dropdown>
                    <i class="el-icon-setting" style="margin-right: 15px"></i>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item>查看</el-dropdown-item>
                        <el-dropdown-item>新增</el-dropdown-item>
                        <el-dropdown-item>删除</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
                <span>{{this.$store.state.user.username}}</span>
            </el-header>

            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
    export default {
        name: "Index",
        data(){
            return{
                functions:[]
            }
        },
        methods:{
            loadUserFunctions(){
                //通过用户名查询权限菜单
                this.$http.get("functions/username/"+this.$store.state.user.username)
                    .then(value => {
                        if(value.data){
                            this.functions = value.data;
                        }
                    })
            }
        },
        mounted() {
            this.loadUserFunctions();
        }
    }
</script>

<style scoped>
    .el-header {
        background-color: #B3C0D1;
        color: #333;
        line-height: 60px;
    }

    .el-aside {
        color: #333;
    }
</style>